package no.ntnu.idi.deid.preprocessor.sentenizer;

import java.util.ArrayList;
import java.util.List;

import no.ntnu.idi.deid.documentunits.Sentence;
import no.ntnu.idi.deid.documentunits.Token;

public class Ngram extends ArrayList<Token[]> {

	private static final long serialVersionUID = 1L;
	Sentence sentence;
	int index; // same as sentence-index;
	int sequence; // integer indicating sequence length: bi-gram, tri-gram..

	public Ngram(Sentence s, int seq) {
		sentence = s;
		index = s.getIndex();
		sequence = seq;
		makeNgrams();
	}

	private void makeNgrams() {
		int numberOfNgrams = sentence.size() - sequence + 1;
		for (int i = 0; i < numberOfNgrams; i++) {
			Token[] temp = new Token[sequence];
			for (int j = 0; j < sequence; j++) {
				temp[j] = sentence.get(i + j);
			}
			add(temp);
		}
	}

	public void print() {
		for (int i = 0; i < size(); i++) {
			for (int j = 0; j < get(i).length; j++) {
				System.out.print(get(i)[j].getStripped() + " ");
			}
			System.out.println();
		}
	}
	
	public String getNGramStrippedString(int i) {
		String returnString = "";
		if(i < size()) {
			Token[] tokens = get(i);
			for(Token token: tokens) {
				returnString += " "+token.getStripped();
			}
		}
		return returnString.trim();
	}
	
	public List<Token> getList(int i) {
		List<Token> list = new ArrayList<Token>();
		for(Token token: get(i)) {
			list.add(token);
		}
		return list;
	}

}
